#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int Is_leap_year(int y)
{

	return ((y % 4 == 0) && (y % 100 != 0) || y % 400 == 0);
}
int main()
{
	int y = 0;
	int m = 0;
	int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	while (scanf("%d %d", &y, &m) == 2)
	{
		int d = arr[m];
		if (Is_leap_year(y)&&m==2)
		{
			d++;
		}
		printf("%d\n", d);
	}
	return 0;
}